//
//  LBCollectionView.m
//  TEXT
//
//  Created by mac on 2025/3/2.
//  Copyright © 2025 刘博. All rights reserved.
//

#import "LBEventCollectionView.h"
#import "LBScrollViewDelegate.h"
#import "LBDelegateCenter.h"

@implementation LBEventCollectionView

- (void)didMoveToWindow
{
    [super didMoveToWindow];
    //执行cell 曝光埋点
}

- (void)reloadData
{
    [super reloadData];
    
   
    [self checkNeedReportLog_auk];
    
}

- (void)checkNeedReportLog_auk
{
    if (!self.window || !self.superview) {
        return;
    }
    // 上报当前visiblecell及其子view的所有埋点，放到下一个runloop,等到cell渲染完成
    
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(performCommitScroll) object:nil];
    [self performSelector:@selector(performCommitScroll) withObject:nil afterDelay:0.5];
    
}

- (void)performCommitScroll
{
    //执行曝光埋点
}

- (LBScrollViewDelegate *)collectionDelegate_auk
{
    if (!_collectionDelegate_auk) {
        _collectionDelegate_auk = [[LBScrollViewDelegate alloc] init];
    }
    return _collectionDelegate_auk;
}

- (void)setDelegate:(id<UICollectionViewDelegate>)delegate
{
    if (delegate == nil) {
//        self.delegateProxy_auk = nil;
        [super setDelegate:nil];
        return;
    }
    
    self.delegateProxy_auk = [[LBDelegateCenter alloc] initWithTarget:self.collectionDelegate_auk proxy:delegate];
    self.delegateProxy_auk.scrollView = self;
    [super setDelegate:(id)self.delegateProxy_auk];
}

- (NSMutableDictionary *)visibleCellInfos_auk
{
    if (!_visibleCellInfos_auk) {
        _visibleCellInfos_auk = [[NSMutableDictionary alloc] init];
    }
    return _visibleCellInfos_auk;
}

- (NSMutableDictionary *)lastVisibleInfos_auk
{
    if (!_lastVisibleInfos_auk) {
        _lastVisibleInfos_auk = [[NSMutableDictionary alloc] init];
    }
    return _lastVisibleInfos_auk;
}

- (NSHashTable *)validViews_auk
{
    if (!_validViews_auk) {
        _validViews_auk = [NSHashTable hashTableWithOptions:NSHashTableWeakMemory];
    }
    return _validViews_auk;
}

- (void)dealloc
{
//    self.delegate = nil;
    _delegateProxy_auk = nil;
    _collectionDelegate_auk = nil;
}

- (BOOL)supportAspectExposure
{
    return NO;
}

@end
